﻿@using Hotel.Application.Dics.Dto;
@model DicCreateUpdateDto
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 文章管理 iframe 框</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="~/layuiadmin/layui/css/layui.css" rel="stylesheet" />
</head>
<body>
    <form class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
        <div class="layui-form-item">
            <label class="layui-form-label">字典名称</label>
            <div class="layui-input-block">
                <input type="text" asp-for="DicName" lay-verify="required" placeholder="请输入字典名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">字典值</label>
            <div class="layui-input-block">
                <input type="text" asp-for="DicValue" lay-verify="required" placeholder="请输入字典名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">字典编码</label>
            <div class="layui-input-block">
                <input type="text" asp-for="DicCode" lay-verify="required" placeholder="请输入字典编码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" value="100" asp-for="DicOrder" lay-verify="number" placeholder="请输入排序" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <input type="hidden" asp-for="TypeId" />
            <input type="hidden" asp-for="DicId" />
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
        </div>
    </form>
    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/layuiadmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'table'], function () {
            var form = layui.form;
            var table = layui.table;
            let Exist = false;
            $("body").on("blur", "#DicName,#DicValue,#DicCode", function () {
                $.ajax({
                    url: "@Url.Action("CheckName")",
                    type: "post",
                    data: $("form").serialize(),
                    success: function (d) {
                        Exist = d.data
                        if (Exist) {
                            layer.msg("字典名称或编码重复", { icon: 5 })
                        }
                    }
                })
            })

            //监听提交
            form.on('submit(layuiadmin-app-form-submit)', function (data) {
                if (Exist) {
                    layer.msg("字典名称或编码重复", { icon: 5 });
                    return false;
                }

                var field = data.field; //获取提交的字段
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引

                //提交 Ajax 成功后，关闭当前弹层并重载表格
                $.ajax({
                    url: "@Url.Action()",
                    type: "post",
                    data: field,
                    success: function (e) {
                        layer.msg("编辑成功", { icon: 6 }, function () {
                            var iframe = parent.document.getElementsByTagName("iframe")[0].contentWindow;
                            iframe.layui.table.reload('data-list'); //重载表格
                            parent.layer.close(index); //再执行关闭
                        });
                    }
                });

                return false;
            });
        })
    </script>
</body>
</html>
